# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
===========================
@Time : 2022/10/10 0010 23:33
@Author : 测试开发工程师
@File : base_page.py
@Software: PyCharm
============================
"""
# 基类：实例化 driver ，封装所有的基本方法

from selenium.webdriver.chrome.webdriver import WebDriver
from selenium import webdriver
from selenium.webdriver.common.by import By


class BasePage:
    _BASE_URL = "https://litemall.hogwarts.ceshiren.com/"

    def __init__(self, driver: WebDriver = None):
        if driver is None:
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()
            # 打开 litemall 网站
            self.driver.get(self._BASE_URL)
        else:
            # 复用 driver
            self.driver = driver

    def do_click(self, by: By, locator: str):
        """
        查找元素并点击
        @param by:
        @param locator:
        """
        self.driver.find_element(by, locator).click()

    def do_send_keys(self, by: By, locator: str, text):
        """
        查找元素并输入
        @param by:
        @param locator:
        @param text:
        """
        element = self.driver.find_element(by, locator)
        # 先清空，再输入
        element.clear()
        element.send_keys(text)
